package com.another.bidservice.controller

import com.another.bidservice.entity.TForm
import com.another.bidservice.service.CommonService
import com.another.common.utils.common.MyException
import com.another.common.utils.result.Result
import com.another.common.utils.result.ResultEnum
import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*


@RestController
@RequestMapping("/common")
@CrossOrigin
open class CommonResource {

    private var logger = Logger.getLogger(this.javaClass)

    @Autowired
    private lateinit var commonService: CommonService

    /**
     * @param form
     * @return com.another.exhibitioncommon.utils.result.Result
     * @author Another
     * @description :  公共接口
     * @date 2020/3/13 15:56:21
     * @version : 1.0
     */
    @PostMapping("/publicAPI")
    @ResponseBody
    open fun publicAPI(@RequestBody form: TForm?): Result? {
        return try {
            commonService?.publicAPI(form)
        } catch (me: MyException) {
            logger.info(me.message, me)
            Result.error(me.code, me.message)
        } catch (e: Exception) {
            logger.info(e.message, e)
            Result.error(
                ResultEnum.UNKONW_ERROR.code,
                ResultEnum.UNKONW_ERROR.msg
            )
        }
    }

}